/*
 * =====================================================================================
 *
 *       Filename:  message_mysql_adapter.h
 *
 *    Description:  declearation for MySql adapter of IM message.
 *
 *        Version:  1.0
 *        Created:  2013年05月10日 17时20分06秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Wu Yuxin (wyx, Hin)
 *        Company:  www.Qihoo.net
 *
 * =====================================================================================
 */

#ifndef __IMSERVER_IM_MESSAGEMYSQLADAPTER_H__
#define __IMSERVER_IM_MESSAGEMYSQLADAPTER_H__

#include <stdint.h>
#include "database/simple_db_pool.h"
#include "ImServiceCommon_types.h"

namespace imserver {

////////////////////////////////////////////////////////////////////////////////////////
// class MessageMysqlAdapter
class MessageMysqlAdapter {
 public:
   explicit MessageMysqlAdapter(const std::string& databse, const std::string& addr, const std::string& user, const std::string& pwd);

   int InsertImMessage(const ImMessage &msg);
   int DeleteImMessage(const int64_t sender, const int64_t receiver, const int64_t seq_id);
   int UpdateReadFlag(const int64_t sender, const int64_t receiver);
   int UpdatereadFlagByID(const std::vector<int64_t> & seq_ids, const int64_t uid);
   int SelectUnreadMessages(ImMessageList& msg_list, const int64_t receiver, const int32_t offset, const int32_t count);
   int SelectReadMessages(ImMessageList& msg_list, const int64_t sender, const int64_t receiver, const int32_t offset, const int32_t limit);

 private:
   int __getImMessages(ImMessageList& list, const char *command);

   base::SimpleConnectionPool  conn_pool_;
};

}

#endif
